package core

import (
	"errors"
	"mytool/base"
	"os"
	"os/exec"
	"runtime"
)

func OpenUrl(args []string) (err error) {
	if len(args) != 2 {
		return errors.New("参数错误")
	}
	if "windows" == runtime.GOOS {
		return exec.Command(`c:\windows\system32\cmd.exe`, "/c start "+args[1]).Start()
	}
	return errors.New("Unsupported platform " + runtime.GOOS)
}

func DoExit(args []string) (err error) {
	os.Exit(0)
	return nil
}

func AppTools() []*base.Option {
	return []*base.Option{
		&base.Option{"exit", DoExit, "退出."},
		&base.Option{"open", OpenUrl, `open <URL> 打开指定URL.`},
	}
}
